package com.zbaohuang.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.joanzapata.android.BaseAdapterHelper;
import com.joanzapata.android.QuickAdapter;
import com.zbaohuang.model.HealthFoodModel;
import com.zbaohuang.model.VolunteerModel;
import com.zbaohuang.xyh.R;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class HealthFoodFragment extends Fragment {


    List<HealthFoodModel> foodModels;

    QuickAdapter<HealthFoodModel> quickAdapter;

    ListView listView;

    View rootView;

    public HealthFoodFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_health_food, container, false);
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        listView = (ListView)rootView.findViewById(R.id.listview);

        foodModels = new ArrayList<HealthFoodModel>();
        foodModels.add(new HealthFoodModel("补气养生粥","功效:补血气，健肠胃","店铺:养生食馆","深圳市南山区学府路1号","40m",R.mipmap.cai1));
        foodModels.add(new HealthFoodModel("春季温补菜","功效:适合春季预防胃病，流感等","店铺:爱康养生","深圳市南山区泉园路1242号","140m",R.mipmap.cai2));
        foodModels.add(new HealthFoodModel("三丝鸡蛋饼","功效:健肠胃、促消化","店铺:爱康养生","深圳市南山区泉园路1242号","140m",R.mipmap.cai3));
        foodModels.add(new HealthFoodModel("筒骨蔬菜煲","功效:补钙、维生素","店铺:民生食馆","深圳市南山区桃园路122号","260m",R.mipmap.cai4));
        foodModels.add(new HealthFoodModel("养生糕点","功效:促食欲、清肠胃","店铺:民生食馆","深圳市南山区桃园路122号","260m",R.mipmap.cai5));

        quickAdapter = new QuickAdapter<HealthFoodModel>(getActivity(),R.layout.item_health_food) {
            @Override
            protected void convert(BaseAdapterHelper helper, HealthFoodModel item) {
                helper.setImageResource(R.id.iconImageView,item.getRes());
                helper.setText(R.id.nameTextView, item.getFoodName());
                helper.setText(R.id.useTextView,item.getFoodUser());
                helper.setText(R.id.bussinesTextView,item.getBusiness());
                helper.setText(R.id.addressTextView,item.getAddress());
                helper.setText(R.id.distanceTextView,item.getDistance());
            }
        };

        listView.setAdapter(quickAdapter);

        quickAdapter.addAll(foodModels);
    }
}
